<?php

class SnsApi
{
    private static $controllerCache;
    private $apiVersion;
    private $token = NULL;

    public function callApi($do, $param, $time, $signature,$appInfo='')/*{{{*/
    {
        $this->callApiStart();

        $systemLimit    =   $this->checkSystemLimit();
        if (!empty(AC::$errorNo))
        {
            return  $this->formatData($systemLimit);
        }
        # check hostUid /*{{{*/
        $hostUid    =   $this->checkHostUid($do);
        if (!empty(AC::$errorNo))
        {
            return  $this->formatData($hostUid);
        }/*}}}*/

        # $param  =   stripslashes($param);
        # check signature
        $checkSignature =   $this->checkSignature($do, $param, $time, $signature);
        if (!empty(AC::$errorNo))
        {
            return  $this->formatData($checkSignature);
        }

        # check $do /*{{{*/
        $doCheck    =   $this->checkDo($do);
        if (!empty(AC::$errorNo))
        {
            return  $this->formatData($doCheck);
        } /*}}}*/

        # get param/*{{{*/
        if (!empty($param))
        {
            $param  =   DOP::decodeData($param);

            if (is_array($param))
            {
                foreach ($param as  &$value)
                {
                    if (is_array($value))   continue;
                    $value  =   trim($value);
                }
            }
        }/*}}}*/

        $result =   $this->$do($param);
        $this->postFeedAndSquare($do);
        $this->itemStatistics();
        $this->userStatistics();
        $this->countLevelExp($do, $param);
        $this->callApiEnd();

        return  $this->formatData($result);
    }/*}}}*/

    public function callSnsApi($do, $param, $time, $signature,$appInfo)/*{{{*/
    {
        if($appInfo!=''){
            $appInfoList=explode(",", $appInfo);
            AC::$appInfoList = $appInfoList;
        }
        $this->iosOrAndroid($appInfo);
        $this->callApiStart();
        
        $systemLimit    =   $this->checkSystemLimit();
        if (!empty(AC::$errorNo))
        {
            return  $this->formatData($systemLimit);
        }
        # check token, hostUid /*{{{*/
        $hostUid    =   $this->checkHostUid($do);
        if (!empty(AC::$errorNo))
        {
            return  $this->formatData($hostUid);
        }
        $tokenInfo  =   $this->checkToken($do);
        if (!empty(AC::$errorNo))
        {
            return  $this->formatData($tokenInfo);
        }/*}}}*/

        # $param  =   stripslashes($param);
        # check signature
        $checkSignature =   $this->checkSignature($do, $param, $time, $signature, $tokenInfo);
        if (!empty(AC::$errorNo))
        {
            return  $this->formatData($checkSignature);
        }

        # check $do /*{{{*/
        $doCheck    =   $this->checkDo($do);
        if (!empty(AC::$errorNo))
        {
            return  $this->formatData($doCheck);
        } /*}}}*/

        # get param/*{{{*/
        if (!empty($param))
        {
           $param  =   DOP::decodeData($param);
            if (is_array($param))
            {
                foreach ($param as  &$value)
                {
                    if (is_array($value))   continue;
                    $value  =   trim($value);
                }
            }
        }/*}}}*/
    
        $result =   $this->$do($param);
        $this->postFeedAndSquare($do);
        $this->itemStatistics();
        $this->userStatistics();
        $this->countLevelExp($do, $param);
        $this->callApiEnd();
        $response = $this->formatData($result);

        $this->sendCollection($time, $signature, $param, $appInfo, $hostUid, $response);
        
        return  $response;
    }/*}}}*/

    # User Api/*{{{*/
    private function registerUser($param)/*{{{*/
    {
        $controller =   $this->newController('UserController');
        $info       =   $controller->registerUser($param);
        if (empty($info))   $info   =   FALSE;
        else
        {
            #   $this->token    =   $this->makeUserToken(__FUNCTION__, $info['uid'], $param);
            $this->makeUserToken(__FUNCTION__, $info['uid'], $param);
        }
        return  $info;
    }/*}}}*/
    private function userLogin($param)/*{{{*/
    {
        $controller =   $this->newController('UserController');
        $info       =   $controller->login($param);
        if (isset($info['userInfo']['uid']))
        {
            $this->checkRegisterUid($info['userInfo']['uid']);

            #   if (empty(AC::$errorNo))    $this->token    =   $this->makeUserToken(__FUNCTION__, $info['userInfo']['uid'], $param);
            if (empty(AC::$errorNo))    $this->makeUserToken(__FUNCTION__, $info['userInfo']['uid'], $param);
            else    $info   =   NULL;
        }
        return  $info;
    }/*}}}*/
    private function emailLogin($param)/*{{{*/
    {
        $controller =   $this->newController('UserController');
        $info       =   $controller->emailLogin($param);
        if (isset($info['userInfo']['uid']))
        {
            $this->checkRegisterUid($info['userInfo']['uid']);

            #   if (empty(AC::$errorNo))    $this->token    =   $this->makeUserToken(__FUNCTION__, $info['userInfo']['uid'], $param);
            if (empty(AC::$errorNo))    $this->makeUserToken(__FUNCTION__, $info['userInfo']['uid'], $param);
            else    $info   =   NULL;
        }
        return  $info;
    }/*}}}*/
    private function openUidLogin($param)/*{{{*/
    {
        $controller =   $this->newController('UserController');
        $info       =   $controller->openUidLogin($param);
        if (isset($info['userInfo']['uid']))
        {
            $this->checkRegisterUid($info['userInfo']['uid']);

            #   if (empty(AC::$errorNo))    $this->token    =   $this->makeUserToken(__FUNCTION__, $info['userInfo']['uid'], $param);
            if (empty(AC::$errorNo))    $this->makeUserToken(__FUNCTION__, $info['userInfo']['uid'], $param);
            else    $info   =   NULL;
        }
        return  $info;
    }/*}}}*/
    private function getUserInfo($param)/*{{{*/
    {
        $controller =   $this->newController('UserController');
        $info       =   $controller->getUserInfo($param);
        return  $info;
    }/*}}}*/
    private function editUserInfo($param)/*{{{*/
    {
        $controller =   $this->newController('UserController');
        $info       =   $controller->editUserInfo($param);
        return  $info;
    }/*}}}*/
    private function modifyUserInfo($param)/*{{{*/
    {
        $controller =   $this->newController('UserController');
        $info       =   $controller->modifyUserInfo($param);
        return  $info;
    }/*}}}*/
    private function updateLoginPasswd($param)/*{{{*/
    {
        $controller =   $this->newController('UserController');
        $info       =   $controller->updateLoginPasswd($param);
        #   $this->token=   md5(AC::HOST_UID);
        #   $this->token=   $this->makeUserToken(__FUNCTION__, $info['userInfo']['uid'], $param);
        $this->makeUserToken(__FUNCTION__, AC::HOST_UID, $param);
        return  $info;
    }/*}}}*/
    private function resetPasswd($param)/*{{{*/
    {
        $controller =   $this->newController('UserController');
        $info       =   $controller->resetPasswd($param);
        return  $info;
    }/*}}}*/
    private function getUserList($param)/*{{{*/
    {
        $controller =   $this->newController('UserController');
        $info       =   $controller->getUserList($param);
        return  $info;
    }/*}}}*/
    private function fetchUserInfo($param)/*{{{*/
    {
        $controller         =   $this->newController('UserController');
        if (empty($param['uid']) && isset($param['nickname']))  $param['nickname']  =   '%'. $param['nickname']. '%';
        $param['fields']    =   'uid, nickname';
        $info               =   $controller->getUserBaseInfoUseLike($param);
        return  $info;
    }/*}}}*/
    // 设置备注
    private function user($param){
        $controller     =   $this->newController('UserController');
        $info           =   $controller->user($param);
        return  $info;
    }
    private function vip($param){
        $controller     =   $this->newController('UserController');
        $info           =   $controller->vipOperate($param);
        return  $info;
    }
    private function getMobileCode($param){
        $controller     =   $this->newController('UserController');
        $info           =   $controller->getMobileCode($param);
        return  $info;
    }
    private function getEmailCode($param){
        $controller     =   $this->newController('UserController');
        $info           =   $controller->getEmailCode($param);
        return  $info;
    }
    private function checkMobileCode($param){
        $controller     =   $this->newController('UserController');
        $info           =   $controller->checkMobileCode($param);
        return  $info;
    }
    private function checkEmailCode($param){
        $controller     =   $this->newController('UserController');
        $info           =   $controller->checkEmailCode($param);
        return  $info;
    }
    private function getUserAccountByEmail($param){
        $controller     =   $this->newController('UserController');
        $info           =   $controller->getUserAccountByEmail($param);
        return  $info;
    }
    private function modifyMobileLoginPasswd($param){
        $controller     =   $this->newController('UserController');
        $info           =   $controller->modifyMobileLoginPasswd($param);
        return  $info;
    }
    private function modifyEmailLoginPasswd($param){
        $controller     =   $this->newController('UserController');
        $info           =   $controller->modifyEmailLoginPasswd($param);
        return  $info;
    }
    private function getCaptcha($param){
        $controller     =   $this->newController('ShareController');
        $info           =   $controller->getCaptcha($param);
        return  $info;
    }
    private function verifyCaptcha($param){
        $controller     =   $this->newController('ShareController');
        $info           =   $controller->verifyCaptcha($param);
        return  $info;
    }
    # end User Api/*}}}*/

    # article Api
    private function article($param){
        $controller     =   $this->newController('ArticleController');
        $info           =   $controller->callApi($param);
        return  $info;
    }
    # end article

    # ability Api
    private function checkAbilityCondition($param){
        $controller     =   $this->newController('UserController');
        $info           =   $controller->abilityCondition($param);
        return  $info;
    }
    private function addAbility($param){
        $controller     =   $this->newController('UserController');
        $info           =   $controller->applyAbility($param);
        return  $info;
    }
    # end ability
    
    # Diary Api/*{{{*/
	private function voteDiary($param)
	{
		$controller =   $this->newController('DiaryController');
		$info       =   $controller->voteDiary($param);
		return  $info;
	}
    private function getDiaryList($param)/*{{{*/
    {
        $controller =   $this->newController('DiaryController');
        $info       =   $controller->getDiaryList($param);
        return  $info;
    }/*}}}*/
    private function getUserDiaryList($param)/*{{{*/
    {
        $controller =   $this->newController('DiaryController');
        $info       =   $controller->getUserDiaryList($param);
        return  $info;
    }/*}}}*/
    private function getDiaryInfo($param)/*{{{*/
    {
        $controller =   $this->newController('DiaryController');
        $info       =   $controller->getDiaryInfo($param);
        return  $info;
    }/*}}}*/
    private function getDiaryInfoWithCommentReply($param)/*{{{*/
    {
        $controller =   $this->newController('DiaryController');
        $info       =   $controller->getDiaryInfoWithCommentReply($param);
        return  $info;
    }/*}}}*/
    private function getDiaryDetail($param)/*{{{*/
    {
        $controller =   $this->newController('DiaryController');
        $info       =   $controller->getDiaryDetail($param);
        return  $info;
    }/*}}}*/
    private function writeDiary($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('DiaryController');
        $info           =   $controller->addDiary($param);
        return  $info;
    }/*}}}*/
    private function shareDiary($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('DiaryController');
        $info           =   $controller->addDiary($param);
        return  $info;
    }/*}}}*/
    private function editDiary($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('DiaryController');
        $info           =   $controller->setDiary($param);
        return  $info;
    }/*}}}*/
    private function removeDiary($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('DiaryController');
        $info           =   $controller->removeDiary($param);
        return  $info;
    }/*}}}*/
    private function fetchDiaryInfo($param)/*{{{*/
    {
        $controller =   $this->newController('HotSquareController');
        if (isset($param['title'])) $param['title']  =   '%'. $param['title']. '%';
        $info       =   $controller->getDiaryInfoUseLike($param);
        return  $info;
    }/*}}}*/
    private function getSearchDiary($param)/*{{{*/
    {
        $controller =   $this->newController('HotSquareController');
        if (isset($param['title'])) $param['title']  =   '%'. $param['title']. '%';
        $info       =   $controller->getSearchDiary($param);
        return  $info;
    }/*}}}*/
    # end Diary Api/*}}}*/

    # Kit Api/*{{{*/
    private function getKitList($param)/*{{{*/
    {
        $controller =   $this->newController('KitController');
        $info       =   $controller->getKitList($param);
        return  $info;
    }/*}}}*/
    private function getKitInfo($param)/*{{{*/
    {
        $controller =   $this->newController('KitController');
        $info       =   $controller->getKitInfo($param);
        return  $info;
    }/*}}}*/
    private function addKit($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('KitController');
        $info           =   $controller->addKit($param);
        return  $info;
    }/*}}}*/
    private function editKit($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('KitController');
        $info           =   $controller->editKit($param);
        return  $info;
    }/*}}}*/
    private function removeKit($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('KitController');
        $info           =   $controller->removeKit($param);
        return  $info;
    }/*}}}*/
    # end Kit Api/*}}}*/

    # Follow Api/*{{{*/
    private function getFollowMeList($param)/*{{{*/
    {
        $controller =   $this->newController('FollowController');
        $info       =   $controller->getFollowMeList($param);
        return  $info;
    }/*}}}*/
    private function getMeFollowList($param)/*{{{*/
    {
        $controller =   $this->newController('FollowController');
        $info       =   $controller->getMeFollowList($param);
        return  $info;
    }/*}}}*/
    private function meFollow($param)/*{{{*/
    {
        $controller =   $this->newController('FollowController');
        $info       =   $controller->meFollow($param);
        return  $info;
    }/*}}}*/
    private function meFollowMany($param)/*{{{*/
    {
        $controller =   $this->newController('FollowController');
        $info       =   $controller->meFollowMany($param);
        return  $info;
    }/*}}}*/
    private function removeFollow($param)/*{{{*/
    {
        $controller =   $this->newController('FollowController');
        $info       =   $controller->removeFollow($param);
        return  $info;
    }/*}}}*/
    private function getBlacklist($param)/*{{{*/
    {
        $controller =   $this->newController('FollowController');
        $info       =   $controller->getBlacklist($param);
        return  $info;
    }/*}}}*/
    private function blacklistFollow($param)/*{{{*/
    {
        $controller =   $this->newController('FollowController');
        $info       =   $controller->blacklistFollow($param);
        return  $info;
    }/*}}}*/
    private function relieveBlacklist($param)/*{{{*/
    {
        $controller =   $this->newController('FollowController');
        $info       =   $controller->relieveBlacklist($param);
        return  $info;
    }/*}}}*/
    # end Follow Api/*}}}*/

    # Feed Api/*{{{*/
    private function getAnnounceList($param){
    	$controller =   $this->newController('FeedController');
    	$info       =   $controller->getAnnounceList($param);
    	return  $info;
    }
    private function getFeedList($param)/*{{{*/
    {
        $controller =   $this->newController('FeedController');
        $info       =   $controller->getFeedList($param);
        return  $info;
    }/*}}}*/
    private function getUserFeedList($param)/*{{{*/
    {
        $controller =   $this->newController('FeedController');
        $info       =   $controller->getUserFeedList($param);
        return  $info;
    }/*}}}*/
    private function removeFeed($param)/*{{{*/
    {
        $controller =   $this->newController('FeedController');
        $info       =   $controller->removeFeed($param);
        return  $info;
    }/*}}}*/
    private function getTimeline($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller =   $this->newController('FeedController');
        $info       =   $controller->getTimeline($param);
        return  $info;
    }/*}}}*/
    private function getLikesMe($param)/*{{{*/
    {
        $controller =   $this->newController('FeedController');
        $info       =   $controller->getLikesMe($param);
        return  $info;
    }/*}}}*/
    private function getFollowLikes($param)/*{{{*/
    {
        $controller =   $this->newController('FeedController');
        $info       =   $controller->getFollowLikes($param);
        return  $info;
    }/*}}}*/
    private function getCommentsToMe($param)/*{{{*/
    {
        $controller =   $this->newController('FeedController');
        $info       =   $controller->getCommentsToMe($param);
        return  $info;
    }/*}}}*/
    private function getCommentsByMe($param)/*{{{*/
    {
        $controller =   $this->newController('FeedController');
        $info       =   $controller->getCommentsByMe($param);
        return  $info;
    }/*}}}*/
    private function getMentions($param)/*{{{*/
    {
        $controller =   $this->newController('FeedController');
        $info       =   $controller->getMentions($param);
        return  $info;
    }/*}}}*/
    private function getCommentsMentions($param)/*{{{*/
    {
        $controller =   $this->newController('FeedController');
        $info       =   $controller->getCommentsMentions($param);
        return  $info;
    }/*}}}*/
    # end Feed Api/*}}}*/
    
    # Lbs Api/*{{{*/
    private function updateUserLocation($param)/*{{{*/
    {
        $controller =   $this->newController('LbsController');
        $info       =   $controller->updateUserLocation($param);
        return  $info;
    }/*}}}*/
    
    private function removeUserLbsInfo($param)/*{{{*/
    {
        $controller =   $this->newController('LbsController');
        $info       =   $controller->removeUserLbsInfo($param);
        return  $info;
    }/*}}}*/
    
    private function getFriendsLocation($param)/*{{{*/
    {
        $controller =   $this->newController('LbsController');
        $info       =   $controller->getFriendsLocation($param);
        return  $info;
    }/*}}}*/
    private function getDiaryByLocation($param)/*{{{*/
    {
        $controller =   $this->newController('LbsController');
        $info       =   $controller->getDiaryByLocation($param);
        return  $info;
    }/*}}}*/
    # end Lbs Api/*}}}*/
    
    # Comment Api/*{{{*/
    private function postComment($param)/*{{{*/
    {
        $controller =   $this->newController('CommentController');
        $info       =   $controller->postComment($param);
        return  $info;
    }/*}}}*/
    private function postReview($param)/*{{{*/
    {
        $controller =   $this->newController('CommentController');
        $info       =   $controller->postReview($param);
        return  $info;
    }/*}}}*/
    private function getCommentInfoList($param)/*{{{*/
    {
        $controller =   $this->newController('CommentController');
        if (empty($param['parentId']))
        {
            $info   =   $controller->getCommentInfoList($param);
        }
        else
        {
            $info   =   $controller->getCommentReplyList($param);
        }
        return  $info;
    }/*}}}*/
    private function getCommentMeList($param)/*{{{*/
    {
        $controller =   $this->newController('CommentController');
        $info       =   $controller->getCommentMeList($param);
        return  $info;
    }/*}}}*/
    private function getMeCommentList($param)/*{{{*/
    {
        $controller =   $this->newController('CommentController');
        $info       =   $controller->getMeCommentList($param);
        return  $info;
    }/*}}}*/
    private function removeComment($param)/*{{{*/
    {
        $controller =   $this->newController('CommentController');
        $info       =   $controller->removeComment($param);
        return  $info;
    }/*}}}*/
    # end Comment Api/*}}}*/

    # Like Api/*{{{*/
    private function postLike($param)/*{{{*/
    {
        $controller =   $this->newController('LikeController');
        $info       =   $controller->postLike($param);
        return  $info;
    }/*}}}*/
    private function getLikeMeList($param)/*{{{*/
    {
        $controller =   $this->newController('LikeController');
        $info       =   $controller->getLikeMeList($param);
        return  $info;
    }/*}}}*/
    private function getMeLikeList($param)/*{{{*/
    {
        $controller =   $this->newController('LikeController');
        $info       =   $controller->getMeLikeList($param);
        return  $info;
    }/*}}}*/
    private function getMeLikeDiaryList($param)/*{{{*/
    {
        $controller =   $this->newController('LikeController');
        $info       =   $controller->getMeLikeDiaryList($param);
        return  $info;
    }/*}}}*/
    private function removeLike($param)/*{{{*/
    {
        $controller =   $this->newController('LikeController');
        $info       =   $controller->removeLike($param);
        return  $info;
    }/*}}}*/
    # end Like Api/*}}}*/

    # Share Api/*{{{*/
    private function postShare($param)/*{{{*/
    {
        $controller =   $this->newController('ShareController');
        $info       =   $controller->postShare($param);
        return  $info;
    }/*}}}*/
    private function getShareMeList($param)/*{{{*/
    {
        $controller =   $this->newController('ShareController');
        $info       =   $controller->getShareMeList($param);
        return  $info;
    }/*}}}*/
    private function getMeShareList($param)/*{{{*/
    {
        $controller =   $this->newController('ShareController');
        $info       =   $controller->getMeShareList($param);
        return  $info;
    }/*}}}*/
    private function removeShare($param)/*{{{*/
    {
        $controller =   $this->newController('ShareController');
        $info       =   $controller->removeShare($param);
        return  $info;
    }/*}}}*/
    # end Share Api/*}}}*/

    # Cloud Sync Api/*{{{*/
    private function cloudSync($param)/*{{{*/
    {
        $controller     =   $this->newController('CloudSyncController');
        $param['uid']   =   AC::HOST_UID;
        $info           =   $controller->cloudSync($param);
        return  $info;
    }/*}}}*/
    private function cloudTraffic($param)/*{{{*/
    {
        $controller     =   $this->newController('CloudSyncController');
        $param['uid']   =   AC::HOST_UID;
        $info           =   $controller->cloudTraffic($param);
        return  $info;
    }/*}}}*/
    private function cloudSyncCount($param)/*{{{*/
    {
        $controller     =   $this->newController('CloudSyncController');
        $info           =   $controller->cloudSyncCount($param);
        return  $info;
    }/*}}}*/
    private function cloudSyncList($param)/*{{{*/
    {
        $controller     =   $this->newController('CloudSyncController');
        $param['uid']   =   AC::HOST_UID;
        $info           =   $controller->cloudSyncList($param);
        return  $info;
    }/*}}}*/
    private function cloudDownload($param)/*{{{*/
    {
        $controller     =   $this->newController('CloudSyncController');
        $param['uid']   =   AC::HOST_UID;
        $info           =   $controller->cloudDownload($param);
        return  $info;
    }/*}}}*/
    private function cloudUpdate($param)/*{{{*/
    {
        $controller     =   $this->newController('CloudSyncController');
        $param['uid']   =   AC::HOST_UID;
        $info           =   $controller->cloudUpdate($param);
        return  $info;
    }/*}}}*/
    private function cloudRemove($param)/*{{{*/
    {
        $controller     =   $this->newController('CloudSyncController');
        $param['uid']   =   AC::HOST_UID;
        $info           =   $controller->cloudRemove($param);
        return  $info;
    }/*}}}*/
    # End Cloud Sync Api/*}}}*/

    # exchange Api  /*{{{*/
    private function getExchangeList($param)/*{{{*/
    {
        $controller =   $this->newController('StatisticsController');
        $info       =   $controller->getExchangeList($param);
        return  $info;
    }/*}}}*/
    # end /*}}}*/

    # Square, Char, Board, Inform Api/*{{{*/
    
    private function getSquareCategory($param)/*{{{*/
    {
        $controller =   $this->newController('HotSquareController');
        $info       =   $controller->getSquareCategory($param);
        return  $info;
    }/*}}}*/
    private function getSquareList($param)/*{{{*/
    {
        $controller =   $this->newController('HotSquareController');
        $info       =   $controller->getSquareList($param);
        return  $info;
    }/*}}}*/
    private function getSquareLatestUserList($param)/*{{{*/
    {
        $controller =   $this->newController('HotSquareController');
        $info       =   $controller->getSquareLatestUserList($param);
        return  $info;
    }/*}}}*/
    private function postChat($param)/*{{{*/
    {
        $controller =   $this->newController('ChatController');
        $info       =   $controller->postChat($param);
        return  $info;
    }/*}}}*/
    private function getChatList($param)/*{{{*/
    {
        $controller =   $this->newController('ChatController');
        $info       =   $controller->getChatList($param);
        return  $info;
    }/*}}}*/

    private function getChosenDiary($param)/*{{{*/
    {
        $controller         =   $this->newController('StatisticsController');
        #   timesType = likeTimes sort use like ，= null or commentTimes , sort use comment 
        $param['timesType'] =   'grossScore';
        $info               =   $controller->getChosenDiary($param);
        return  $info;
    }/*}}}*/
    private function getHotDiary($param)/*{{{*/
    {
        $controller         =   $this->newController('StatisticsController');
        #   timesType = likeTimes sort use like ，= null or commentTimes , sort use comment
        $param['timesType'] =   'grossScore';
        $info               =   $controller->getHotDiary($param);
        return  $info;
    }/*}}}*/
    private function getHotRecommendDiary($param)/*{{{*/
    {
        $controller         =   $this->newController('StatisticsController');
        $param['timesType'] =   'grossScore';
        $info               =   $controller->getHotRecommendDiary($param);
        return  $info;
    }/*}}}*/
    private function getChosenCommentDiary($param)/*{{{*/
    {
        $controller         =   $this->newController('StatisticsController');
        #   $param['timesType'] =   'commentTimes';
        $param['timesType'] =   'grossScore';
        $info               =   $controller->getChosenDiary($param);
        return  $info;
    }/*}}}*/
    private function getChosenLikeDiary($param)/*{{{*/
    {
        $controller         =   $this->newController('StatisticsController');
        $param['timesType'] =   'likeTimes';
        $info               =   $controller->getChosenDiary($param);
        return  $info;
    }/*}}}*/
    private function getChosenByEditor($param)/*{{{*/
    {
        $controller         =   $this->newController('StatisticsController');
        $info               =   $controller->getChosenByEditor($param);
        return  $info;
    }/*}}}*/
    private function deviceInfo($param)
    {
        $controller         =   $this->newController('UserController');
        $info               =   $controller->deviceInfo($param);
        return  $info;
    }
    private function submitDevice($param)
    {
        $controller         =   $this->newController('UserController');
        $info               =   $controller->submitDevice($param);
        return  $info;
    }

    private function getRealtimeBoard($param)/*{{{*/
    {
        $board  =   array(
            'chat'  =>  '签到，话题回复楼层跳转、点赞，群组等级，粉粉圈全新分类，欢迎更新。',
            'square'=>  '签到，话题回复楼层跳转、点赞，群组等级，粉粉圈全新分类，欢迎更新。',
        );
        if (empty($board[$param['module']]))    return  NULL;

        $result =   array('content' =>  $board[$param['module']]);
        return  $result;
    }/*}}}*/
    private function postBoard($param)/*{{{*/
    {
        $controller =   $this->newController('ChatController');
        $info       =   $controller->postBoard($param);
        return  $info;
    }/*}}}*/
    private function updateBoard($param)/*{{{*/
    {
        $controller =   $this->newController('ChatController');
        $info       =   $controller->updateBoard($param);
        return  $info;
    }/*}}}*/
    private function removeBoard($param)/*{{{*/
    {
        $controller =   $this->newController('ChatController');
        $info       =   $controller->removeBoard($param);
        return  $info;
    }/*}}}*/
    private function getBoardList($param)/*{{{*/
    {
        $controller =   $this->newController('BoardController');
        $info       =   $controller->getBoardList($param);
        return  $info;
    }/*}}}*/

    private function postInform($param)/*{{{*/
    {
        $controller =   $this->newController('InformController');
        $info       =   $controller->postInform($param);
        return  $info;
    }/*}}}*/
    private function updateInform($param)/*{{{*/
    {
        $controller =   $this->newController('InformController');
        $info       =   $controller->updateInform($param);
        return  $info;
    }/*}}}*/
    private function removeInform($param)/*{{{*/
    {
        $controller =   $this->newController('InformController');
        $info       =   $controller->removeInform($param);
        return  $info;
    }/*}}}*/
    private function getInformList($param)/*{{{*/
    {
        $controller =   $this->newController('InformController');
        $info       =   $controller->getInformList($param);
        return  $info;
    }/*}}}*/
    private function postReport($param)/*{{{*/
    {
        $controller =   $this->newController('InformController');
        $info       =   $controller->postReport($param);
        return  $info;
    }/*}}}*/
    # End Square, Char, Board, Inform Api/*}}}*/

    # Web Message Api /*{{{*/
    private function sendMessage($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('MessageBoxController');
        $info           =   $controller->sendMessage($param);
        return  $info;
    }/*}}}*/
    private function removeMessage($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('MessageBoxController');
        $info           =   $controller->removeMessage($param);
        return  $info;
    }/*}}}*/
    private function getMessageList($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('MessageBoxController');
        $info           =   $controller->getMessageList($param);
        return  $info;
    }/*}}}*/
    private function getMessageInfo($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('MessageBoxController');
        $info           =   $controller->getMessageInfo($param);
        return  $info;
    }/*}}}*/
    private function getMessageInbox($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('MessageBoxController');
        $info           =   $controller->getMessageInbox($param);
        return  $info;
    }/*}}}*/
    private function getMessageOutbox($param)/*{{{*/
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('MessageBoxController');
        $info           =   $controller->getMessageOutbox($param);
        return  $info;
    }/*}}}*/

    private function getEmotionList($param)
    {
        $param['uid']   =   AC::HOST_UID;
        $controller     =   $this->newController('MessageBoxController');
        $info           =   $controller->getEmotionList($param);
        return  $info;
    }
    # End Web Message Api /*}}}*/
    
    # Sns Manage Api!/*{{{*/
    private function postManage($param)/*{{{*/
    {
        $controller     =   $this->newController('ManageController');
        $info           =   $controller->callApi($param);
        return  $info;
    }/*}}}*/
    # End Sns Manage Api/*}}}*/
    
    # recommentUserList /*{{{*/
    private function recommentUserList($param)/*{{{*/
    {
    	$controller     =   $this->newController('HotSquareController');
    	$info           =   $controller->recommentUserList($param);
    	return  $info;
    }/*}}}*/
    private function getRecommentUsers($param)/*{{{*/
    {
        $controller     =   $this->newController('HotSquareController');
        $info           =   $controller->getRecommentUsers($param);
        return  $info;
    }/*}}}*/
    # recommentUserList /*}}}*/
    
    # Push API /*{{{*/
    private function push($param)/*{{{*/
    {
    	$controller         =   $this->newController('PushController');
    	$info          	    =   $controller->callApi($param);
    	return  $info;
    }/*}}}*/
    # Push end /*}}}*/
    
    # Sns Group API /*{{{*/
    private function group($param)/*{{{*/
    {
    	$controller         =   $this->newController('GroupController');
    	$info          	    =   $controller->callApi($param);
    	return  $info;
    }/*}}}*/
    # END Sns Group API /*}}}*/
    
    # Sns shop API /*{{{*/
    private function shop($param)/*{{{*/
    {
        $param['uid']       =   AC::HOST_UID;
        $controller         =   $this->newController('ShopController');
        $info          	    =   $controller->callApi($param);
        return  $info;
    }/*}}}*/
    # END Sns shop API /*}}}*/
    
    # Sns Common API /*{{{*/
    private function common($param)/*{{{*/
    {
    	$controller         =   $this->newController('ShareController');
    	$info          	    =   $controller->callApi($param);
    	return  $info;
    }/*}}}*/
    # END Sns Share API /*}}}*/
    
    # Sns groupChat API /*{{{*/
    private function groupChat($param)/*{{{*/
    {
        $controller         =   $this->newController('LikeController');
        $info          	    =   $controller->callApi($param);
        return  $info;
    }/*}}}*/
    # END Sns groupChat API /*}}}*/
    
    private function chatRoom($param)
    {
        $controller         =   $this->newController('ChatroomController');
        $info          	    =   $controller->callApi($param);
        return  $info;
    }
    
    # GEO
    private function lbs($param){
        $controller =   $this->newController('LbsController');
        $info       =   $controller->callApi($param);
        return $info;
    }
    
    # comment
    private function comment($param) {
        $controller =   $this->newController('CommentController');
        $info       =   $controller->callApi($param);
        return $info;
    }
    
    # diary
    private function diary($param) {
        $controller =   $this->newController('DiaryController');
        $info       =   $controller->callApi($param);
        return $info;
    }

    private function anonymous($param) {
        $controller =   $this->newController('AnonymousController');
        $info       =   $controller->callApi($param);
        return $info;
    }

    private function robot($param) {
        $controller =   $this->newController('RobotController');
        $info       =   $controller->callApi($param);
        return $info;
    }
    
    # Sns doTask API /*{{{*/
    private function doTask($param)/*{{{*/
    {
        $controller         =   $this->newController('ShareController');
        $info          	    =   $controller->doTask($param);
        return  $info;
    }/*}}}*/
    # END Sns doTask API /*}}}*/
    
    # Sns guest API /*{{{*/
    private function guest($param)/*{{{*/
    {
        $controller         =   $this->newController('GuestController');
        $info          	    =   $controller->callApi($param);
        return  $info;
    }/*}}}*/
    # END Sns guest API /*}}}*/

    # Sns imSupport API /*{{{*/
    private function imSupport($param)/*{{{*/
    {
        $param['op'] = $param['action'];
        $controller         =   $this->newController('ImSupportController');
        $info          	    =   $controller->callApi($param);
        return  $info;
    }/*}}}*/
    # END Sns imSupport API /*}}}*/

    # Sns Api system check!/*{{{*/
    private function checkSystemLimit()/*{{{*/
    {
        return  TRUE;
        AC::$errorNo    =   'SA006';
        #   $ip =   UK::getClientIp();
        #   return  ' system limit ';
        return  ' 服务器正在维护中！请稍候访问。';
    }/*}}}*/
    private function checkDo($do)/*{{{*/
    {
        if (method_exists($this, $do))  return  TRUE;

        AC::$errorNo    =   'SA004';
        return  " Error : call do[$do] is not exists! ";
    }/*}}}*/
    private function checkSignature($do, $param, $time, $signature, $tokenInfo = NULL)/*{{{*/
    {
        #   return  TRUE;
        #   $do, $hostUid, $param, $time, $key;

        if (1   ==  AC::API_VERSION)
            $crypt  =   $do. AC::HOST_UID. $param. $time. AC::MD5_KEY;
        else
        {
            #   $crypt  =   $do. AC::HOST_UID. $param. $time. $token;
            $doStatus   =   $this->checkDoStatus($do);
            if (empty($doStatus))
            {
                $tToken =   $this->cryptToken($tokenInfo['token']);
            }
            else
            {
                $tToken =   $tokenInfo['token'];
            }
            if (empty($tToken)  ||  !empty(AC::$errorNo))
            {
                unset($tokenInfo['token']);
                return  $tokenInfo;
                #   return  'Signature token is error ! ';
            }
            $crypt  =   $do. AC::HOST_UID. $param. $time. $tToken;
        }
        $md5Crypt   =   md5($crypt);

        if ($signature  ==  $md5Crypt)  return  TRUE;
        AC::$errorNo    =   'SA003';
        unset($tokenInfo['token']);
        #   $tokenInfo['result']    =   ' Signature error! md5("'. $crypt. '") => checkSignature = "'. $md5Crypt. '" | tokenInfo='. $tokenInfo['token']. ' | tToken = '. $tToken. '| paramSignature = "'. $signature. '" ';
        return  $tokenInfo;
    }/*}}}*/
    private function cryptToken($token) /*{{{*/
    {
        #   if (empty($token))  return  'ffrj@SNS';
        $length =   strlen($token);
        if (32  !=  $length)
        {
            AC::$errorNo    =   'SA011';
            return  $token;
        }
        $cryptString=   substr($token, 2, 3);
        $cryptNum   =   hexdec($cryptString);
        $cryptBase  =   $cryptNum % 8;

        $cryptArray =   array(
                            0   =>  array( 0,  1,  3,  7, 15, 31),
                            1   =>  array( 7, 15, 31,  0,  1,  3),
                            2   =>  array( 4,  5,  7, 11, 19,  3),
                            3   =>  array(19,  3,  4,  5,  7, 11),
                            4   =>  array(18, 19, 21, 25,  1, 17),
                            5   =>  array(25,  1, 17, 18, 19, 21),
                            6   =>  array(27, 28, 30,  2, 10, 26),
                            7   =>  array( 2, 10, 26, 27, 28, 30),
                        );

        $tmpToken   =   NULL;
        foreach ($cryptArray[$cryptBase]    as  $id)
        {
            $tmpToken   .=  $token[$id];
        }
        return  $tmpToken;
    }/*}}}*/
    private function checkHostUid($do)/*{{{*/
    {
        $doStatus   =   $this->checkDoStatus($do);
        if (TRUE    ==  $doStatus)  return  TRUE;

        $info   =   $this->checkRegisterUid(AC::HOST_UID);
        if (empty($info['uid']) ||  AC::HOST_UID != $info['uid'])
        {
            if (empty(AC::$errorNo))
            {
                AC::$errorNo    =   'SA002';
                return  ' Error : hostUid is empty! ';
            }
            else
            {
                return  $info;
            }
        }

        AC::$hostUserBaseInfo   =   $info;
        return  $info['uid'];
    }/*}}}*/
    private function checkDoStatus($do)/*{{{*/
    {
        $unCheckDo  =   array(
                            'registerUser'      =>  1,
                            'userLogin'         =>  1,
                            'resetPasswd'       =>  1,
                            'openUidLogin'      =>  1,
                            'getExchangeList'   =>  1,
                            'guest'             =>  1,
                            'getMobileCode'     =>  1,
                            'getEmailCode'      =>  1,
                            'checkMobileCode'   =>  1,
                            'checkEmailCode'    =>  1,
                            'getUserAccountByEmail' => 1,
                            'modifyMobileLoginPasswd' => 1,
                            'modifyEmailLoginPasswd' => 1,
                            'getCaptcha'        => 1,
                            'verifyCaptcha'     => 1,
                            #   'getSquareList' =>  1,
                            #   'getChatList'   =>  1,
                        );

        if (isset($unCheckDo[$do])) return  TRUE;
        return  FALSE;
    }/*}}}*/
    private function checkToken($do)/*{{{*/
    {
        # version 1, don't check token!
        if (1   ==  AC::API_VERSION)    return  TRUE;

        $doStatus   =   $this->checkDoStatus($do);
        if (TRUE    ==  $doStatus)  return  array('token' => 'ffrj@SNS');

        $tokenInfo  =   $this->getUserToken(AC::HOST_UID);
        # version > 1
        if (empty($tokenInfo['token']))
        {
            AC::$errorNo    =   'SA008';
            return  ' Error : No Login token! ';
        }
        #   if (md5(AC::HOST_UID)   !=  $token)
        #   {
        #       AC::$errorNo    =   'SA009';
        #       return  ' Error : Token is wrong! ';
        #   }
        # token is expiration 
        # AC::$errorNo  =   'SA010';

        return  $tokenInfo;
    }/*}}}*/
    private function checkRegisterUid($uid)/*{{{*/
    {
        $controller =   $this->newController('UserController');
        $info       =   $controller->getUserCacheInfo($uid);
        if (!empty($info['status']))
        {
            AC::$errorNo    =   'SA007';
            AC::$errorMsg   =   '粉粉id:'.$uid.'，您的账号有违规操作已禁用，请发邮件联络粉粉管理员' . SERVICE_MAIL_ADDR . '申诉[错误码:SA007]';
            return  FALSE;
        }
        return  $info;
    }/*}}}*/
    private function getUserToken($uid)/*{{{*/
    {
        #   return  array('token' => md5($uid));
        $controller =   $this->newController('UserController');
        $info       =   $controller->getUserToken(array('uid' => $uid));
        return  $info;
    }/*}}}*/
    private function makeUserToken($do, $uid, $param)/*{{{*/
    {
        if (1   ==  AC::API_VERSION)    return  TRUE;

        if (!empty(AC::$errorNo))   return  FALSE;
        if (empty($do)  ||  empty($uid))
        {
            AC::$errorNo    =   'SA005';
            return  FALSE;
        }
        #   $this->token    =   md5($uid);
        #   return  array('token' => md5($uid));
        $controller     =   $this->newController('UserController');
        $param['do']    =   $do;
        $param['uid']   =   $uid;
        $info           =   $controller->makeUserToken($param);
        $this->token    =   $info;
        #   return  $info;
    }/*}}}*/
    # end System check!/*}}}*/
    # service logic/*{{{*/
    private function postFeedAndSquare($do)/*{{{*/
    {
        if (empty(AC::$feedInfo['authorUid'])   ||  empty(AC::$feedInfo['eUid']))   return  TRUE;
        if (isset(AC::$feedInfo['diaryVideoNeedReview']) && AC::$feedInfo['diaryVideoNeedReview'])return true;

        # post Feed
        $controller =   $this->newController('FeedController');
        $info       =   $controller->postFeed(AC::$feedInfo);

        # post Square: must user original content
        $squareType =   array(
                            'writeDiary'    =>  1,
                            'addKit'        =>  1,
                            'group'         =>  1,
                            'article'       =>  1,
                        );
        if (!empty($squareType[$do]))
        {
            $controller =   $this->newController('HotSquareController');
            $info       =   $controller->postSquare(AC::$feedInfo);
        }

        return  TRUE;
    }/*}}}*/
    private function itemStatistics()/*{{{*/
    {
        if (empty(AC::$itemStatistics['bodyidTypeClass']))  return  NULL;

        if ('diary' ==  AC::$itemStatistics['bodyidTypeClass'])
        {
            $newController  =   'DiaryController';
        }
        else
        {
            $newController  =   'KitController';
        }
        $controller =   $this->newController($newController);
        $controller->countTimes(AC::$itemStatistics);
        return  TRUE;
    }/*}}}*/
    private function userStatistics()/*{{{*/
    {
        if (empty(AC::$userStatistics)  ||  !is_array(AC::$userStatistics)) return  NULL;

        $controller =   $this->newController('UserStatisticsController');
        foreach (AC::$userStatistics    as  $uid => $statistics)
        {
            if (empty($uid) ||  empty($statistics)) continue;

            $statistics['uid']  =   $uid;
            $controller->userStatistics($statistics);
        }
        return  TRUE;
    }/*}}}*/
    private function countLevelExp($do, $param)/*{{{*/
    {
        if (!empty(AC::$errorNo))   return  NULL;
        $isadmin = false;
        if(AC::$userExpAction['action']){
        	$data['uid']            =   AC::HOST_UID;
        	if(AC::$userExpAction['admin'] && AC::$userExpAction['userid'] > 0){
        		$data['uid']        = AC::$userExpAction['userid'];
        		$isadmin = true;
        	}
        	$data['profitType']     =   AC::$userExpAction['action'];
        	$data['profitTimes']    =   ExpLevel::$typeGainTimes[$data['profitType']];
        	$data['profit']         =   ExpLevel::$typeGainExp[$data['profitType']];
        	
        	$controller     =   $this->newController('UserController');
        	AC::$profitInfo =   $controller->countLevelExp($data, $isadmin);
        	return  TRUE;
        }

        $doArray    =   array(
                            'shareDiary'    =>  'diaryTimes',
                            'postComment'   =>  'commentTimes',
                            'postReview'   =>  'commentTimes',
                            'postLike'      =>  'likeTimes',
                            'commentDiary'  =>  'commentTimes'
                        );
        // 新版评论
        if ($do == 'comment' && $param['action'] == 'commentDiary') {
            $do = 'commentDiary';
        }
        
        // group
        $groupArray =   array(
                            'addTopic'      =>   'addTopicTimes',
                            'postTopicComment' => 'postTopicCommentTimes',
                        );
        $data = array();
        // 圈子增加经验
        if ($do == 'group' && !empty($groupArray[$param['action']])){
            $data['uid']            =   AC::HOST_UID;
            $data['profitType']     =   $groupArray[$param['action']];
            $data['profitTimes']    =   ExpLevel::$typeGainTimes[$data['profitType']];
            $data['profit']         =   ExpLevel::$typeGainExp[$data['profitType']];

            $controller     =   $this->newController('UserController');
            AC::$profitInfo =   $controller->countLevelExp($data);
            return  TRUE;
        }
        if (empty($doArray[$do]))   return  NULL;
        
        $data['uid']            =   AC::HOST_UID;
        $data['profitType']     =   $doArray[$do];
        $data['profitTimes']    =   ExpLevel::$typeGainTimes[$data['profitType']];
        $data['profit']         =   ExpLevel::$typeGainExp[$data['profitType']];
        
        $controller     =   $this->newController('UserController');
        AC::$profitInfo =   $controller->countLevelExp($data);

        if (!empty(AC::$errorNo))   AC::$errorNo    =   NULL;
        if ('postLike'  !=  $do)    return  TRUE;
        $data['uid']            =   $param['lUid'];
        $data['profitType']     =   'likedTimes';
        $data['profitTimes']    =   ExpLevel::$typeGainTimes['likedTimes'];
        $data['profit']         =   ExpLevel::$typeGainExp['likedTimes'];

        $controller =   $this->newController('UserController');
        $info       =   $controller->countLevelExp($data);

        if (!empty(AC::$errorNo))   AC::$errorNo    =   NULL;
        return  TRUE;
    }/*}}}*/
    
    private function callApiStart()/*{{{*/
    {
        return  NULL;
    }/*}}}*/
    private function callApiEnd()/*{{{*/
    {
        return  NULL;
    }/*}}}*/

    private function sendCollection($time, $signature, $param, $appInfo, $hostUid, $response) {
        $collection_url = "http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
        list($OS, $platform) = UK::getOsAndPlantform(AC::$appInfoList);
        $collection_params = array(
            'time'         =>    $time,
            'signature'    =>    $signature,
            'param'        =>    $param,
            'appInfo'      =>    $appInfo,
            'hostUid'      =>    $hostUid,
            'os'           =>    $platform,
            'idfa'         =>    DOP::request('idfa'),
            'deviceId'     =>    AC::$appInfoList[5]
        );
        $this->collection($collection_url, 'post', $collection_params, $response);
    }

    private function collection($url, $method, $params, $response){
        global $_G;
        $response = DOP::decodeData($response);
        $response['resultData'] = '';
        $clollectionData = array(
            'source'   =>    $_G['serverHost'],
            'url'      =>    $url,
            'method'   =>    $method,
            'params'   =>    $params,
            'response' =>    $response
        );
        $clollectionDataOfJson = DOP::encodeData($clollectionData);
        RedisPool::addCollectionGearmanJob("collection", $clollectionDataOfJson);
    }
    private function formatData($result)/*{{{*/
    {
        if (empty(AC::$errorNo))    AC::$errorNo    =   NULL;
        else
        {
            $data['param']  =   DOP::request('param');
            $data['do']     =   DOP::request('do');
            $data['date']   =   AC::SERVER_DATE_TIME;
        }

        $data['resultData'] =   $result;
        $data['serverTime'] =   AC::SERVER_TIME;
        $data['errorNo']    =   AC::$errorNo;
        // 错误信息
        $data['errorMsg']   =   AC::$errorMsg;
        $data['profitInfo'] =   AC::$profitInfo;
        // 金币
        if (AC::$gainCoin){
            $data['profitInfo']['gainCoin'] = AC::$gainCoin;
        }
        // 经验
        if (AC::$gainExp){
            $data['profitInfo']['gainExp'] = AC::$gainExp;
        }
        if (1   !=  AC::API_VERSION)
        {
            if (!empty($this->token)){   
                $data['token']  =   $this->token;
                $data['resultData']['token']  =   $this->token;
            }
        }

        $result =   DOP::encodeData($data);
        if (AC::$errorNo && AC::$errorNo != 'SA002')
        {
//            file_put_contents('/tmp/errorNo.txt', $result. "\r\n\r\n", FILE_APPEND);
        }

        return  $result;
    }/*}}}*/
    # end service logic/*}}}*/
    
    # ios or android
    private function iosOrAndroid($appInfo){
        if (empty($appInfo)){
            AC::$userVersion = 1;
            return TRUE;
        }

        $product        =    AC::$appInfoList[0];
        $product_version=    AC::$appInfoList[1];
        $os             =    AC::$appInfoList[2];
        $os_version     =    AC::$appInfoList[3];
        $device         =    AC::$appInfoList[4];
        $deviceKey      =    AC::$appInfoList[5];
        $deviceVersion  =    strtolower($product.$os);

        // 发送匿名评论
        $version_arr = array(
            'pinkdiaryandroid'              =>  '5.70',
            'pinkdiaryios'                  =>  '5.7.0'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '>=', AC::$anonymousCommentVerdion);

        // 订阅号打赏
        $version_arr = array(
            'pinkdiaryandroid'              =>  '5.60',
            'pinkdiaryios'                  =>  '5.6.0'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '>=', AC::$subscriptionVersion);

        //新版本取消关注vip提醒
		$removeFollow = array(
			'pinkdiaryandroid'          =>  '5.10',
			'pinkdiaryios'              =>  '5.1.0',
		);
		$this->checkAllPlatformVersion($product_version, $removeFollow, $deviceVersion, '<', AC::$removeFollowVersion);
		//新版本字体预览图
		$font_version = array(
			'pinkdiaryandroid'          =>  '5.00',
			'pinkdiaryios'              =>  '5.0.0',
		);
		$this->checkAllPlatformVersion($product_version, $font_version, $deviceVersion, '<', AC::$fontCoverVersion);

		//会员任务老版本支持
		$member_version = array(
			'pinkdiaryandroid'          =>  '4.97',
			'pinkdiaryios'              =>  '4.9.7',
		);
		$this->checkAllPlatformVersion($product_version, $member_version, $deviceVersion, '<', AC::$member);

        //4.9皮肤priview
        $version_arr = array(
            'pinkdiaryandroid'          =>  '4.90',
            'pinkdiaryios'              =>  '4.9.0',
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$skinPriviewVersion);
        
        $actions = array(
        		'getPlannerTagsList','getPlannerPapersList','getPlannerStickersList',
        		'getPlannerBrushsList','getPlannerTempletsList',
        		'getPlannerTagsDetail','getPlannerPapersDetail',
        		'getPlannerStickersDetail','getPlannerBrushsDetail',
        		'getPlannerTempletsDetail','getMyPlannerPapersList',
        		'getMyPlannerStickersList','getMyPlannerTagsList',
        		'getMyPlannerBrushsList','getMyPlannerTempletsList',
        		'getPlannerNewStickersList','getPlannerNewTagsList','getPlannerNewBrushsList'
        );
        $paramJson = DOP::request('param');
        $action    = json_decode($paramJson,'true');
	
        //ios手账标签
        if($deviceVersion =='pinkdiaryios' && version_compare($product_version, '4.5.1', '<=')  ){
            if(in_array($action['action'],$actions)){
                AC::$iosPlannerTagVersion = 1;
            }	
        }
	
        //手账资源
        if($deviceVersion =='pinkdiaryandroid' && version_compare($product_version, '4.21', '<=')  ){
            if(in_array($action['action'],$actions)){
                AC::$plannerVersion = 1;
            }
        }
	
        //女生认证
        $version_arr = array(
            'pinkdiaryandroid'          =>  '4.22',
            'pinkdiaryios'              =>  '4.5.1',	
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$femaleVersion);
        
        // userversion
        $version_arr = array(
            'pinkdiaryandroid'          =>  '3.58',
            'pinkdiaryios'              =>  '2.2.7',
            'pinksnsios'                =>  '1.1.1'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$userVersion);
        
        // 语音支持
        $version_arr = array(
            'pinkdiaryandroid'          =>  '3.75',
            'pinkdiaryios'              =>  '1.4.0',
            'pinksnsios'                =>  '1.4.0'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$userVoiceVersion);
        
        // 话题转发支持
        $version_arr = array(
            'pinkdiaryandroid'          =>  '3.76',
            'pinkdiaryios'              =>  '1.4.1',
            'pinksnsios'                =>  '1.4.1'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$topicFdVersion);

        // 热门新格式支持
        $version_arr = array(
            'pinkdiaryandroid'          =>  '3.87',
            'pinkdiaryios'              =>  '1.4.8',
            'pinksnsios'                =>  '1.4.8',
            'com.xxtstudio.iosdevios'   =>  '2.3.6'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$hotWidgetVersion);

        // 私信，群聊附件支持
        $version_arr = array('pinkdiaryandroid'  =>  '3.89');
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$chatAttachmentVersion);
        
        // 表情显示支持
        $version_arr = array(
            'pinkdiaryandroid'          =>  '3.93',
            'pinkdiaryios'              =>  '2.4.1',
            'pinksnsios'                =>  '2.4.1',
            'com.xxtstudio.iosdevios'   =>  '2.4.1'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$emotionShowVersion);
        
        // 话题表情显示支持
        $version_arr = array(
            'pinkdiaryios'              =>  '2.4.2',
            'com.xxtstudio.iosdevios'   =>  '2.4.2'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$emotionTopicShowVersion);
        
        // 日记信纸ios显示支持
        $version_arr = array('com.xxtstudio.iosdevios'   =>  '2.4.0');
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$paperIosDiaryShowVersion);
        
        // 标签推荐
        $version_arr = array(
            'pinkdiaryios'              =>  '2.4.3',
            'pinksnsios'                =>  '2.4.3',
            'com.xxtstudio.iosdevios'   =>  '2.4.3'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$recommentByTagVersion);
        // 大转盘分享支持
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$shareSupportVersion);
        
        // 表情显示支持
        $version_arr = array('pinkdiaryandroid'  =>  '3.98');
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$retweetShareImgVersion);
        
        // 完整版
        $version_arr = array('pinkdiaryproios'   =>  '1.1.0');
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '>=', AC::$iosFullVersion);

        // 附件个数
        $version_arr = array(
            'pinkdiaryandroid'          =>  '4.10',
            'pinkdiaryios'              =>  '4.3.0',
            'pinkdiaryproios'           =>  '2.0.0'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$topicDiaryAttachmentLimit, 'attachment');

        // 解绑手机号后，再次绑定手机失败，密码不正确
        $version_arr = array(
            'pinkdiaryios'              =>  '4.7.0',
            'pinkdiaryproios'           =>  '4.7.0'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '==', AC::$fixPasswdVersion);
	
	// 私信推送关闭
        $version_arr = array(
            'pinkdiaryandroid'          =>  '4.37',
            'pinkdiaryios'              =>  '4.8.1',
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '>=', AC::$closeBdMsgpushVersion);

        //打开发送群组消息、私信同步到im
        $version_arr = array(
            'pinkdiaryandroid'          =>  '4.37',
            'pinkdiaryios'              =>  '4.8.1',
            'pinkdiaryproios'           =>  '4.7.0'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<', AC::$openSendChatMsg2IMVersion);
        //打开群组vip申请判断
        $version_arr = array(
            'pinkdiaryandroid'          =>  '4.96',
            'pinkdiaryios'              =>  '4.9.6',
            'pinkdiaryproios'           =>  '4.7.0'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '>', AC::$openApplyGroupVipVersion);

        //点滴视频支持
        $version_arr = array(
            'pinkdiaryandroid'          =>  '4.98',
            'pinkdiaryios'              =>  '4.9.9'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '>=', AC::$video_version);

        //ios https
        $version_arr = array(
            'pinkdiaryios'              =>  '4.9.5',
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '>=', AC::$https_version);
        
        // 为你推荐IOS显示老数据
        $version_arr = array(
            'pinkdiaryios'              =>  '4.8.0',
            'pinkdiaryproios'           =>  '4.7.0'
        );
        $this->checkAllPlatformVersion($product_version, $version_arr, $deviceVersion, '<=', AC::$recommendIosVersion);

        return TRUE;
    }
    
    private function checkAllPlatformVersion ($os_version, $version_arr, $platform, $operate = '', &$result = 0, $type = '') {
        if (isset($version_arr[$platform])) {
            $check = version_compare($os_version, $version_arr[$platform],  $operate);
            if ($check) {
                if ($type === 'attachment') {
                    $result = 6;
                }else{
                    $result = intval(abs($result - 1));
                }
            }
        }
        
    	return $result;
    }
    
    # new controller    /*{{{*/
    private function newController($controller)
    {
        if (empty($controller))
        {
            AC::$errorNo    =   'SA001';
            return  FALSE;
        }
        if (isset(self::$controllerCache[$controller])  &&  is_resource(self::$controllerCache[$controller]))
        {
            return  self::$controllerCache[$controller];
        }
        self::$controllerCache[$controller] =   new $controller();
        return  self::$controllerCache[$controller];
    }/*}}}*/

}

